package com.chengjue.controller;

import javax.annotation.Resource;

import com.chengjue.jms.activemq.queue.QueueSender1;
import com.chengjue.jms.activemq.topic.TopicSender1;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Description: <br/>
 *
 * @author hetiewei
 * @date 2016年4月25日 上午10:35:31
 *
 */
@RestController
@RequestMapping("activemq")
public class ActivemqController {

    @Resource
    private QueueSender1 queueSender;
    @Autowired
    private TopicSender1 topicSender;

    /**
     * 发送消息到队列
     * Queue队列：仅有一个订阅者会收到消息，消息一旦被处理就不会存在队列中
     * @param message
     * @return String
     */
    @RequestMapping("queueSender/{message}")
    public String queueSender(@PathVariable("message")String message){
        String opt="";
        try {
            queueSender.send("test.queue", message);
            opt = "suc";
        } catch (Exception e) {
            opt = e.getCause().toString();
        }
        return opt;
    }

    @RequestMapping("topicSender/{message}")
    public String topoicSender(@PathVariable("message")String message){
        String opt = "";
        try {
            topicSender.send("test.topic", message);
            opt = "suc";
        } catch (Exception e) {
            opt = e.getCause().toString();
        }
        return opt;
    }


}
